from gi.repository import Gtk , Gdk, Vte, GLib, Pango

# 可关闭的标签组件

class ClosableTab(Gtk.Box): 

    def __init__(self, label_text, notebook,term): 
        super(ClosableTab, self).__init__()
        self.label_text = label_text
        label = Gtk.Label(label_text)
        self.notebook = notebook
        self.term = term
        icon = Gtk.Image()
        icon.set_from_file("images/close.svg")
        btn_close = Gtk.ToolButton()
        btn_close.set_icon_widget(icon)
        self.pack_start(label, True,True, 0)
        self.pack_end(btn_close, False,False, 0)
        self.show_all()
        btn_close.connect("button_release_event",self.close_clicked)
        self.label = label

    def close_clicked(self, widget, event):
        self.notebook.close_term(self.term)
        return True

    def set_text(self,text):
        self.label.props.label = text
        self.label_text = text


